package com.new_wear.project.system.visits.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.new_wear.framework.aspectj.lang.annotation.Log;
import com.new_wear.framework.aspectj.lang.enums.BusinessType;
import com.new_wear.project.system.visits.domain.CstVisits;
import com.new_wear.project.system.visits.service.ICstVisitsService;
import com.new_wear.framework.web.controller.BaseController;
import com.new_wear.framework.web.domain.AjaxResult;
import com.new_wear.common.utils.poi.ExcelUtil;
import com.new_wear.framework.web.page.TableDataInfo;

/**
 * 系统 - 三端平台访问记录Controller
 * 
 * @author new_wear
 * @date 2020-01-08
 */
@Controller
@RequestMapping("/system/visits")
public class CstVisitsController extends BaseController
{
    private String prefix = "system/visits";

    @Autowired
    private ICstVisitsService cstVisitsService;

    @RequiresPermissions("system:visits:view")
    @GetMapping()
    public String visits()
    {
        return prefix + "/visits";
    }

    /**
     * 查询系统 - 三端平台访问记录列表
     */
    @RequiresPermissions("system:visits:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CstVisits cstVisits)
    {
        startPage();
        List<CstVisits> list = cstVisitsService.selectCstVisitsList(cstVisits);
        return getDataTable(list);
    }

    /**
     * 导出系统 - 三端平台访问记录列表
     */
    @RequiresPermissions("system:visits:export")
    @Log(title = "系统 - 三端平台访问记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CstVisits cstVisits)
    {
        List<CstVisits> list = cstVisitsService.selectCstVisitsList(cstVisits);
        ExcelUtil<CstVisits> util = new ExcelUtil<CstVisits>(CstVisits.class);
        return util.exportExcel(list, "visits");
    }

    /**
     * 新增系统 - 三端平台访问记录
     */
    /*@GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }*/

    /**
     * 新增保存系统 - 三端平台访问记录
     */
    @RequiresPermissions("system:visits:add")
    @Log(title = "系统 - 三端平台访问记录", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult addSave(String ip)
    {
        CstVisits cstVisits = new CstVisits();
        cstVisits.setDevice("PC");
        cstVisits.setIp(ip);
        cstVisits.setDuration(30);
        cstVisits.setAddTime(new Date());

        return toAjax(cstVisitsService.insertCstVisits(cstVisits));
    }

    /**
     * 修改系统 - 三端平台访问记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        CstVisits cstVisits = cstVisitsService.selectCstVisitsById(id);
        mmap.put("cstVisits", cstVisits);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统 - 三端平台访问记录
     */
    @RequiresPermissions("system:visits:edit")
    @Log(title = "系统 - 三端平台访问记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CstVisits cstVisits)
    {
        return toAjax(cstVisitsService.updateCstVisits(cstVisits));
    }

    /**
     * 删除系统 - 三端平台访问记录
     */
    @RequiresPermissions("system:visits:remove")
    @Log(title = "系统 - 三端平台访问记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cstVisitsService.deleteCstVisitsByIds(ids));
    }
}
